﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SWDataDB.DAL;
using SWDataDB.BLL;
using System.Data;
using SWDataDB.Models;
public partial class Admin_PMManage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            bind();
        }
    }



    //绑定数据源
    private void bind()
    {
        PMInfo pmquery = new PMInfo();

        DataSet ds = pmquery.GetAllInfoBySet();
        DataTable dt = ds.Tables[0];
        DataView dv = dt.DefaultView;
        //对用于分页的类的引用
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = dt.DefaultView;//设置数据源(DataTable类型)
        pds.AllowPaging = true;


        AspNetPager1.RecordCount = dv.Count;
        pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
        pds.PageSize = AspNetPager1.PageSize;
        PMRepeater.DataSource = pds;
        PMRepeater.DataBind();
    }






    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        bind();
    }








    protected void PMRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

        if (e.CommandName.Equals("DelData"))
        {
            PMInfo pmDel = new PMInfo();
            int delId = Convert.ToInt32(e.CommandArgument);
            if (pmDel.DeletePMInfoById(delId) == 1)//从PM表中删除指定id的PM
            {
                bind();
                Response.Write("<script language=javascript>alert('删除成功！');location='PMManage.aspx'</script>");
                //Response.Redirect("ZLManage.aspx");
            }
            else
            {
                Response.Write("<script language=javascript>alert('删除失败！');location='PMManage.aspx'</script>");
            }
        }



    }




    //批量删除
    protected void btnDel_Click(object sender, EventArgs e)
    {
        //先遍历取得选中项
        for (int i = 0; i < this.PMRepeater.Items.Count; i++)
        {
            CheckBox cbx = (CheckBox)PMRepeater.Items[i].FindControl("cbx");
            Label lbl = (Label)PMRepeater.Items[i].FindControl("LBL");



            if (cbx != null)
            {
                if (cbx.Checked)
                {
                    PMInfo zlDels = new PMInfo();
                    string id = lbl.Text.ToString();
                    int delIds = Convert.ToInt32(id);
                    zlDels.DeletePMInfoById(delIds);
                }
            }
        }

        bind();
    }


    protected void theSearchBtn_Click(object sender, ImageClickEventArgs e)
    {
        QDAdvanceQuery qdquery = new QDAdvanceQuery();
        string strFileID =  Request.Form["FileID"];
        string strtitleName = Request.Form["titleName"];
        string strPMCODE = Request.Form["PMCODE"];
        string strPMName = Request.Form["PMName"];
        string strPMQuality = Request.Form["PMQuality"];
        string strPMScale = Request.Form["PMScale"];
        string strPMSLON1 = Request.Form["PMSLON1"];
        string strPMSLON2 = Request.Form["PMSLON2"];
        string strPMSLAT1 = Request.Form["PMSLAT1"];
        string strPMSLAT2 = Request.Form["PMSLAT2"];

        DataSet ds = qdquery.PMInfoQuery(strFileID, strtitleName, strPMCODE, strPMName, strPMQuality, strPMScale, strPMSLON1, strPMSLON2, strPMSLAT1, strPMSLAT2);
        DataTable dt = ds.Tables[0];
        DataView dv = dt.DefaultView;
        //对用于分页的类的引用
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = dt.DefaultView;//设置数据源(DataTable类型)
        pds.AllowPaging = true;


        AspNetPager1.RecordCount = dv.Count;
        pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
        pds.PageSize = AspNetPager1.PageSize;
        PMRepeater.DataSource = pds;
        PMRepeater.DataBind();
    }

}